package com.pn.controller;

import com.pn.entity.ProductType;
import com.pn.entity.Result;
import com.pn.service.ProductTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/productCategory")
@RestController
public class ProductTypeController {

    @Autowired
    private ProductTypeService productTypeService;

    /*查询商品分类url接口productCategory/product-category-tree*/
    @RequestMapping("/product-category-tree")
    public Result productTypeTree() {
        return Result.ok(productTypeService.productTypeTree());
    }

    /*校验商品分类编码是否重复url接口productCategory/verify-type-code*/
    @RequestMapping("/verify-type-code")
    public Result verifyTypeCode(String typeCode) {
        return productTypeService.verifyTypeCodeOrName(typeCode);
    }

    /*添加商品分类url接口productCategory/type-add*/
    @RequestMapping("/type-add")
    public Result addProductType(@RequestBody ProductType productType) {
        return productTypeService.saveProductType(productType);
    }

    /*删除商品分类url接口/type-delete/*/
    @RequestMapping("/type-delete/{typeId}")
    public Result removeType(@PathVariable Integer typeId) {
        return productTypeService.removeProductTypeById(typeId);
    }

    /*修改商品分类url接口/type-update*/
    @RequestMapping("/type-update")
    public Result setProductType(@RequestBody ProductType productType) {
        return productTypeService.setProductTypeById(productType);
    }
}
